﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2011
// admin@franknagl.de
//
namespace SBIP.Controls
{
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.Xna.Framework.Graphics;

    /// <summary>
    /// Shows an image or a texture in a separate independent window.
    /// </summary>
    /// 
    /// <remarks> 
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = new Bitmap("Cathedral.jpg");
    /// new SimpleImageViewer(image);
    /// // with a texture
    /// Texture2D texture;
    /// Helper.ImageConverter.BitmapToTexture(
    ///        image, graphicsDevice, out texture);
    /// new SimpleImageViewer(texture);
    /// </code>
    /// 
    /// <para><b>Example:</b></para>
    /// <img src="../../SimpleImageViewer.jpg" width="500" height="347" />
    /// </remarks>
    /// 
    public partial class SimpleImageViewer : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleImageViewer"/> class.
        /// </summary>
        /// <param name="tex">The texture to show.</param>
        public SimpleImageViewer(Texture2D tex)
        {
            InitializeComponent();
            Bitmap bitmap = new Bitmap(
                Helper.BitmapToTexture.TextureTo24Bit(tex), 
                ImagePanel.Width, 
                ImagePanel.Height);
            ImagePanel.BackgroundImage = bitmap;
            Show();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleImageViewer"/> class.
        /// </summary>
        /// <param name="bitmap">The bitmap to show.</param>
        public SimpleImageViewer(Bitmap bitmap)
        {
            InitializeComponent();
            bitmap = new Bitmap(bitmap, ImagePanel.Width, ImagePanel.Height);
            ImagePanel.BackgroundImage = bitmap;
            Show();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleImageViewer"/> class.
        /// </summary>
        /// <param name="bitmap">The bitmap to show.</param>
        /// <param name="title">The title.</param>
        public SimpleImageViewer(Bitmap bitmap, string title)
            : this(bitmap)
        {
            Text = title;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleImageViewer"/> class.
        /// </summary>
        /// <param name="tex">The texture to show.</param>
        /// <param name="title">The title.</param>
        public SimpleImageViewer(Texture2D tex, string title)
            : this(tex)
        {
            Text = title;
        }
    }
}
